home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 472 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.8 KB

  1. Path: cs.uwa.edu.au!jasonb
  2. From: jasonb@cs.uwa.edu.au (Jason S Birch)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: PPC compilers
  5. Date: 8 Jan 96 10:51:43 GMT
  6. Organization: The University of Western Australia
  7. Message-ID: <jasonb.821098303@cs.uwa.edu.au>
  8. References: <john.hendrikx.40ka@grafix.xs4all.nl> <4b77tq$htp@serpens.rhein.de> <MQAQx*XOe@yaps.rhein.de> <4bqhnf$6g5@sunsystem5.informatik.tu-muenchen.de> <jasonb.820051107@cs.uwa.edu.au> <4c9i2l$h3i@sunsystem5.informatik.tu-muenchen.de> <4cf0ep$233@ra.i  <4ck47h$g07@maureen.teleport.com> <jasonb.820919731@cs.uwa.edu.au> <4com6v$415@maureen.teleport.com>
  9. NNTP-Posting-Host: decadence.cs.uwa.oz.au
  10. X-Newsreader: NN version 6.5.0 #3 (NOV)
  11.  
  12. sschaem@teleport.com (Stephan Schaem) writes:
  13.  
  14. >Jason S Birch (jasonb@cs.uwa.edu.au) wrote:
  15. >: sschaem@teleport.com (Stephan Schaem) writes:
  16. >: >Lars Duening (duening@ibr.cs.tu-bs.de) wrote:
  17. >: >: If a have to access hardware registers (never had to so far), I will
  18. >: >: not do this by direct pointers, but instead define a structure
  19. >: >: representing them. This is then the only place where I have to worry
  20.                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  21. >: >: about .c, .w and .l, everywhere else I can write 
  22.       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  23. >: >: 'chipregs->blt0con = *b++;' and let the compiler figure the rest out.
  24.       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  25. >: >: HLLs win again here: the compiler will warn if *b is of the wrong
  26.                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  27. >: >: type, and if I defined the structure wrong (your .w/.l example), I
  28.       ^^^^
  29. >: >: just have to correct the structure, not the n statements where it is
  30. >: >: used. And the compiler would even take care of bitshifts where
  31. >: >: necessary.
  32.  
  33. >: > You let the compiler tell you AFTER you write your code about the type?
  34.  
  35. >: That's not what he said. He said the only place he has to worry about .c, .w
  36. >: and .l is where he's defining his structures (although even then, it would be
  37. >: extremely rare) and after that he can just use his new types, relying on the
  38. >: compiler to give a warning if he's made a mistake.
  39.  
  40. > I dont think he can declare like this:   chipregs.bltcon0  con0;
  41. > So he will need so 'worry' about it when he declare con0, he will
  42. > read ushort when peeking the structure (Like the asm coder) or
  43. > maybe he typedefed  ushort  chipreg; and will use this instead.
  44. > *b could be a pointer to float for all he cares, dont you think its
  45. > wise to know what data your are manipulating so you can declare your
  46. > variable correctly?!?!
  47.  
  48. Again: *If* he's trying to create a data type with certain
  49. implementation-dependent size-requirements (such as in the bltcon0
  50. case, assuming no headers to give us one) *then*, at that point in
  51. time, he has to know the size of the type in order to define it
  52. correctly. He stated that earlier - check what I've underlined.
  53. However, once done, he can then safely create variables of that type
  54. (the abstract one he's defined, which happens to be the right size) and
  55. safely assign appropriate values to them, without having to worry if
  56. the eventual assignments are implemented as a .c, .w, or .l. He can
  57. safely rely on the compiler to produce the correct code, and warn him
  58. if he's trying to assign an inappropriate value. *b must be a pointer
  59. to the correct type that he's defined, and as he said, the compiler
  60. will warn him if *b is the wrong type. That's all.
  61.  
  62. >: He needs to know how he's defined it, yes - but not whether it turns into a .c,
  63. >: .w, or .l. It could be written as a UCHAR, a LONG, or even typedef'd to a
  64. >: BILBY. Read it again.
  65.  
  66. > He needs to know how he declared it too... meaning he has to know when
  67. > he write the code what is the type on bltcon0.. a uword or a BILBY (typdef
  68. > for uword)... And if he as a few brain cell left he will remember that
  69. > when he use the variable. EX when I declare float, long in a function
  70. > I know wich is wich otherwise I might store a float temp result
  71. > in a long and bang!
  72.  
  73. The question is not about whether you need to know if a variable is a
  74. float or a long, since they are "abstract" types (and can be different
  75. sizes on different machines). The question is whether you need to know
  76. how many bits are in each, and what each bit means. In assembler, you
  77. do need to know the former, and occasionally the latter.
  78.  
  79. >: > Yea, I agree... move.w (ax)+,(a1)+ just mean : "Copy 2 bytes from a0 to
  80. >: > a1, and increment both address by 2"
  81. >: > In C the equivalent to move.? (a0)+,(a1)+ is
  82. >: > A++ = B++;
  83. >: > And that beying defined somewhere:
  84. >: > ushort    *A,*B;
  85.  
  86. >: That's only the C equivalent on certain platforms. C itself says nothing about
  87. >: the actual size of its various types, other than a relative ordering.
  88.  
  89. > ANSI define very well the minimum size of its type.
  90.  
  91. It does *not* define that ushort is the same as two bytes, which is
  92. what you are claiming above as being equivalent. It only guarantees
  93. that char <= short <= long.
  94.  
  95. > Yes, thats very true... in asm you only have fixed type. But typedef is
  96. > not really a part of the compiler but preprocessor, and could be easely
  97. > integrated to an assembler.(But its not, so its hell when you modify
  98. > structure)
  99.  
  100. >#typedef .w .chipreg
  101.  
  102. > move.chipreg    (GLOBAL_x1,a4),(CHIPREG_bltcon0,a1)
  103.  
  104. typedef really is part of the compiler, not the preprocessor.
  105. Unfortunately, given the notice C takes of typedefs you've made, it
  106. may as well be part of the preprocessor. :-( 
  107. (ie. typedef xxx foo;
  108.      typedef xxx bar;
  109.  
  110.      foo x;
  111.      bar y;
  112.  
  113. I would hope x = y to at least give a warning, even if they are
  114. actually the same type.)
  115.  
  116. > Stephan
  117.  
  118. -- 
  119. Jason S Birch                        ,-_|\ email: jasonb@cs.uwa.edu.au
  120. Department of Computer Science      /     \ Tel (work): +61 9 380 1840
  121. The University of Western Australia *_.-._/ Fax (work): +61 9 380 1089
  122. Nedlands  W. Australia  6907             v  Tel (home): +61 9 386 8630
  123.